<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2021/11/25
  Time: 10:32
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>主页面</title>
    <link rel="stylesheet" href="${r}/css/book.css">
    <style>
        .add {
            padding-bottom: 1em;
            width: 100%;
            display: flex;
            justify-content: space-between;
            margin-top: 15px;
        }
 /*       header span {
            padding: 2em 2em;
            margin-left: 1050px;
        }*/
        header {
            display: grid;
            grid-template-columns: 1fr auto;
        }
        header span {
            padding: 2em 1em;
        }
        h3 {
            text-align: center;
            margin-left: 200px;
        }
    </style>
</head>
<body>
    <header>
    <h3>余文乐图书管理系统</h3>
<%--        empty session.user 是判断用户为空
            not empty session.user 是判断用户不为空
--%>
        <span>
<%--            如果用户还没有登录，就显示“登录和注册”--%>
            <c:if test="${empty sessionScope.user}">
                <a href="${r}/book/login">登录</a>
                ||
                <a href="${r}/book/register">注册</a>
            </c:if>
<%--            如果用户已经登录，则显示”登录成功“之后的用户信息--%>
            <c:if test="${sessionScope.user != null}">
                欢迎您：${user.username}
                <a href="${r}/book/logout">点击注销</a>
            </c:if>
        </span>
    </header>

<%--    如果用户登录了，就允许使用添加方法--%>
    <c:if test="${sessionScope.user != null}">
        <div>
            <form action="${r}/book/add" method="post" class="add">
                <input type="text" name="name" placeholder="图书名称">
                <input type="text" name="author" placeholder="图书作者">
                <input type="number" name="price" placeholder="图书价格">
                <input type="text" name="press" placeholder="图书出版社">
                <input type="text" name="sales" placeholder="图书销量">
                <button>添加书籍</button>
            </form>
        </div>
    </c:if>

    <div>
        <form action="${r}/book/vague">
            <input name="condition" placeholder="请输入查询条件（图书名称或图书出版社）" style="width: 260px; height: 25px">
            <button>搜索按钮</button>
        </form>
    </div>

    <table>
        <tr>
            <th>图书编号</th>
            <th>图书名称</th>
            <th>图书作者</th>
            <th>图书价格</th>
            <th>图书出版社</th>
            <th>图书销量</th>
<%--            如果用户登录了就显示操作功能这一栏--%>
            <c:if test="${sessionScope.user != null}">
                <th>操作功能</th>
            </c:if>
        </tr>
        
        <c:forEach var="book" items="${xxx}">
            <tr>
                <td>${book.id}</td>
                <td>${book.name}</td>
                <td>${book.author}</td>
                <td>${book.price}</td>
                <td>${book.press}</td>
                <td>${book.sales}</td>
<%--                如果用户登录了就显示“删除和修改”--%>
                <c:if test="${sessionScope.user != null}">
                    <td>
                        <a href="${r}/book/del?id=${book.id}">删除</a>
                        ||
                        <a href="${r}/book/update?id=${book.id}">修改</a>
                    </td>
                </c:if>
            </tr>
        </c:forEach>
    </table>

<%--    页脚--%>
    <%@include file="/footer.jsp"%>
</body>
</html>
